﻿@{
    Layout = "~/Views/Shared/_Index.cshtml";
}
<div class="ibox-content">
    <form class="form form-horizontal" id="form" autocomplete="off">
        <input type="hidden" name="id" id="id" value="@(ViewBag.Id)">
        <div class="form-group">
            <label class="col-sm-3 control-label">父项：</label>
            <div class="col-sm-4">
                @Html.DropDownList("parent_id", ViewBag.DicSelList as SelectList, new { @class = "form-control" })
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label required">字典名称：</label>
            <div class="col-sm-4">
                <input type="text" name="dic_name" id="dic_name" value="" class="form-control" data-rule="required">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">字典编码：</label>
            <div class="col-sm-4">
                <input type="text" name="dic_code" id="dic_code" value="" class="form-control">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label required">排序：</label>
            <div class="col-sm-4">
                <input type="text" name="sort_num" id="sort_num" class="form-control" data-rule="required;integer; range[1~1000]">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-9">
                <textarea name="remark" id="remark" cols="60" rows="4"></textarea>
            </div>
        </div>
        <div class="hr-line-dashed"></div>
        <div class="footerbar">
            <div class="col-sm-12 col-sm-offset-3">
                <button class="btn btn-primary" type="submit">保存内容</button>
                <button class="btn btn-white" type="button" onclick="cancel()">取消</button>
            </div>
        </div>
    </form>
</div>

@section scripts{
    <script type="text/javascript">
        var index = parent.layer.getFrameIndex(window.name);
        $(function () {
            $('#form').validator({
                stopOnError: false,
                timely: 2,
                theme: "yellow_right",
                valid: function (form) {
                    // 表单验证通过，提交表单
                    jutils.ajaxPost('/admin/sysdic/savedata', $(form).serialize(),
                        function (res) {
                            parent.layer.close(index);
                        });
                }
            });

            loadData();
        });


        function loadData() {
            var id = $("#id").val();

            if (id !== '') {
                jutils.ajaxGet('/admin/sysdic/GetdicById', { id: id }, function (res) {
                    $('#form').initFormData(res.data.model);
                });
            }
        }

        function cancel() {
            parent.layer.close(index);
        }
    </script>


}





